#include "emulator.h"

//定时器相关
int32 b_timer_data = 0;
int32 b_timer_time = 0;

//定时器运行标识
int b_timer_started = 0;

int32 mr_timer(void)
{
	/*
	if (mr_timer_state != MR_TIMER_STATE_RUNNING){
		MRDBGPRINTF("warning:mr_timer event unexpected!");
		return MR_IGNORE;
	}
	mr_timer_state = MR_TIMER_STATE_IDLE;

	if ((mr_state == MR_STATE_RUN) || ((mr_timer_run_without_pause) && (mr_state == MR_STATE_PAUSE))){
	}else if  ( mr_state == MR_STATE_RESTART){
		mr_stop();                     //1943 修改为mr_stop
		_mr_intra_start(start_filename, NULL);
		return MR_SUCCESS;
	}else{
		return MR_IGNORE;
	};


	if (mr_timer_function){
		int status = mr_timer_function();
		if(status!=MR_IGNORE)
			return status;
	}
*/
	mr_testComC(vm, 801, NULL, 1, 2);
	return 1;
}

//到时间
void vm_timeOut()
{
	logi("vm_timeOut()");
	mr_timer();
}

//虚拟的定时器回调，定时调用他即可
int vm_timerCb(void *data){
	if(b_timer_started)
	if(mr_getTime(vm)-b_timer_data>=b_timer_time)
	{
		mr_printf("mr_timer_cb(%d)",b_timer_time);
		b_timer_data = mr_getTime(vm);
		vm_timeOut();
	}
	return 0;
}

//定时器启动
int32 mr_timerStart(uint16 t){
	logi("mr_timerStart(%d)",t);
	b_timer_started = TRUE;
	b_timer_time = t;
	b_timer_data = mr_getTime(vm);
	return 1;
}

//停止定时器
int32 mr_timerStop(void){
	logi("mr_timerStop()");
	b_timer_started = FALSE;
	b_timer_data = mr_getTime(vm);
	return 1;
}

